<template>
  <div>
    <!-- <van-nav-bar
      title="账号登录"
      left-text=""
      left-arrow
      @click-left="onClickLeft"
      class="login_title"
      color="white"
    /> -->
    <TopTitle :texttitle="'账号登录'" :gourl="'/home/profile'"></TopTitle>

    <van-form @submit="onSubmit" class="from-vant">
      <van-field
        v-model="username"
        name="username"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请填写用户名' }]"
        class="vant-from-information"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
        class="vant-from-information"
      />
      <div style="margin: 16px">
        <van-button
          block
          type="info"
          native-type="submit"
          color="#21b97a"
          class="vant-from-btn"
          >登 录</van-button
        >
      </div>
    </van-form>
    <router-link to="/registe" class="goRegiste"
      >还没有账号？去注册~</router-link
    >
  </div>
</template>

<script>
import { login } from '@/api/Interface'
import {setToken} from '@/utils/storage'
import TopTitle from '@/components/TopTitle.vue'

export default {
  name: 'login',
  components:{
    TopTitle
  }
  ,
  data() {
    return {
      color: '#21b97a',
      username: '',
      password: '',
    }
  },
  methods: {
    // onClickLeft() {
    //   this.$router.push('/home/profile')
    // },
    async onSubmit(values) {
      console.log('submit', values)
      const res = await login(values)
      if (res.description === '账号登录成功') {
        this.$toast.success(res.description)
        setToken(res.body.token)
        this.$router.push('/home/profile')
      } else {
        this.$toast.fail(res.description)
      }
    },
  },
}
</script>

<style scoped lang="less">
.login_title {
  background-color: #21b97a !important;
}
.van-nav-bar__title {
  color: #fff;
}
.goRegiste {
  color: #666;
  font-size: 14px;
  margin: 30px auto;
  display: block;
  text-align: center;
}
.from-vant {
  margin-top: 30px;
  .vant-from-information {
    height: 60px;
    width: 345px;
    font-size: 17px;
    margin: 10px auto;
    padding: 0 0 0 5px;
    line-height: 50px;
    border-bottom: 1px solid rgba(0, 0, 0, 0);
  }
  .vant-from-btn {
    width: 345px;
    height: 50px;
    font-size: 18px;
    line-height: 50px;
  }
}
</style>
